﻿<%dim respagecode%><% 'UTF-8%>

<% ''投诉单管理%>
<% ''加载通用函数和数据库连接%>
<!--#include file="../Include/Start.asp"-->
<!--#include file="../Include/check_Permissions_do.asp"-->

<%
	'定义json对象
	Dim jsonObj,jsonObj_user
	Set jsonObj = jsObject()
	Set jsonObj_user = jsObject()
	UserID=ReplaceBadChar(Trim(Session("UserID")))
	
	dim act 
  	act=request("act")
  	
 	Dim rsObj,strSql
 	set rsObj=Server.CreateObject("ADODB.Recordset")
	Dim page ''当前查询页
	Dim RowCount''影响的记录条数
	''查询信息
	''id, code编码, cname名称, c_key键值, c_txt显示文字, sort_num排序序号 、 pid父节点id
	dim cid, code, cname, c_key, c_txt, sort_num, pid
 
	''查询信息列表
	if "search"=act then
		page=ReplaceBadChar(Trim(request.Form("page")))&""
		cid=ReplaceBadChar(Trim(request.Form("cid")))''id 序列号
		code=ReplaceBadChar(Trim(request.Form("code")))'' 
		cname=ReplaceBadChar(Trim(request.Form("cname")))'' 
		c_key=ReplaceBadChar(Trim(request.Form("c_key")))'' 
		c_txt=ReplaceBadChar(Trim(request.Form("c_txt")))'' 
		pid=ReplaceBadChar(Trim(request.Form("pid")))'' 
 				
		jsonObj("rslist") = ""
		''添加用户信息
		jsonObj_user("UserID") = UserID 
		jsonObj_user("UserName") =ReplaceBadChar(Trim(Session("UserName")))
		Set jsonObj("customer") = jsonObj_user 
		 


		''处理key值和value的对应关系--end	
		
		If ("" = UserID ) Then UserID = "-999hasd9huoad9e993jwoi982niuh9wncdisj99"
	 
		''添加查询结果信息
		''Dim rsObj,strSql
 
		strSql = " SELECT top 100 PERCENT uew.id as orderid1 "  
		strSql =  strSql & " ,uew.id, uew.code, uew.name, uew.c_key, uew.c_txt, uew.sort_num,uew.pid  "		
		strSql =  strSql & " FROM [T_数据字典] uew  where 1=1 "
		if (""<>cid) then strSql =  strSql & " and uew.id = '" & cid & "'  " end if
		if (""<>code) then strSql =  strSql & " and uew.code  like '%" & code & "%'  " end if  ''
		if (""<>cname) then strSql =  strSql & " and uew.name  like '%" & cname & "%'  " end if  ''
		if (""<>c_key) then strSql =  strSql & " and uew.c_key like '%" & c_key & "%'  " end if  ''
		if (""<>c_txt) then strSql =  strSql & " and uew.c_txt  like '%" & c_txt & "%'  " end if ''
		if (""<>pid) then strSql =  strSql & " and uew.pid  = '" & pid & "'  " end if ''
		strSql =  strSql & " ORDER BY uew.orderid1, uew.code, uew.sort_num" 

 		dim TotalRsNum ,PageSizeCur''TotalRsNum总记录数''PageSizeCur当前页记录数
		strSqlTemp = "select count(*)  from ( " & strSql & " ) kksds "
		TotalRsNum = PE_CLng(Conn.Execute(strSqlTemp)(0))
		''PageSize 页的记录数量
		PageSizeCur = PageSize ''当前页记录数
		if (PageSize*PE_CLng(page)>TotalRsNum or 0=TotalRsNum) then ''判断最后一页记录数是否和PageSize相等
			PageSizeCur= TotalRsNum Mod PageSize ''该页的实际记录数
		end if

		strSqlTemp = " SELECT ttkkk.* FROM (SELECT TOP " & CStr(PageSizeCur)
		strSqlTemp = strSqlTemp & "  mmsss.* FROM (SELECT TOP " & CStr(PageSize*PE_CLng(page)) & " nnfff.* FROM ( " 
		strSqlTemp = strSqlTemp &	strSql  
		strSqlTemp = strSqlTemp &  " ) nnfff) mmsss  ORDER BY mmsss.orderid1 DESC) ttkkk ORDER BY ttkkk.orderid1"
		''Response.Write strSqlTemp&"------<br>"
		Set jsonObj("rslist") = QueryToJSON(Conn, strSqlTemp)
 
 
 
		
		''添加分页信息
		'定义json对象
		Dim jsonObj_page
		Set jsonObj_page = jsObject()
			jsonObj_page("PageCur") = Page ''当前页	
			jsonObj_page("PageSizeCur") = PageSizeCur ''当前页记录数
			if (0=TotalRsNum  mod PageSize  ) then
				jsonObj_page("PageTotalNum")= TotalRsNum\PageSize''总页数
			else
				jsonObj_page("PageTotalNum")= TotalRsNum\PageSize+1''总页数
			end if
		Set jsonObj("page") = jsonObj_page 
		jsonObj("success") = 1 'false
	  	jsonObj("msg") = "记录查询成功！"
	 
	''查询tree信息列表
	elseif "tree"=act then
		dim root
		root=ReplaceBadChar(Trim(request("root")))&"" 
 				
 		Dim jsonObj_map 
		Set jsonObj_map = jsArray()		
		set jsonObj_map(0) = jsObject()
		jsonObj_map(0)("id") = "0"
		jsonObj_map(0)("text") = "数据字典"
		jsonObj_map(0)("hasChildren") = true 
		''Response.Write root&"------root----<br>"
		if ("-1"=root) then 
			Set jsonObj =  jsonObj_map''输出主节点
		else''输出子节点		 
			''添加查询结果信息
			''Dim rsObj,strSql
			strSql = " SELECT DISTINCT  COUNT(dfg.id) AS hasChildren, uew.id, uew.name AS text,   "  
			strSql =  strSql & " uew.code, uew.c_key, uew.c_txt, uew.sort_num,   uew.ppath, uew.pid  "  
			strSql =  strSql & " FROM [T_数据字典] uew LEFT OUTER JOIN [T_数据字典] dfg ON uew.id = dfg.pid "
			strSql =  strSql & " GROUP BY dfg.id, uew.id, uew.name, uew.code, uew.c_key, "
			strSql =  strSql & "   uew.c_txt, uew.sort_num, uew.ppath, uew.pid,  uew.ppath "
			if (""<>root) then strSql =  strSql & " HAVING uew.pid = '" & root & "'  " end if
			strSql =  strSql & " ORDER BY uew.pid, uew.sort_num " 	
		
			''Response.Write strSql&"------<br>"
			Set jsonObj= QueryToJSON(Conn, strSql)
		end if 
	 
	''查询tree信息列表
	elseif "dic_sel"=act then
		pid=ReplaceBadChar(Trim(request("pid")))&"" 
		''Response.Write pid&"----pid--<br>"
		
	 
		''添加查询结果信息
		''Dim rsObj,strSql
		strSql = "SELECT uew.* FROM T_数据字典 uew  WHERE 1=2 "
		if (""<>pid) then strSql =  strSql & " or uew.pid = '"&pid&"'"  end if	
		strSql =  strSql & " ORDER BY uew.code , uew.sort_num  "
	
		''Response.Write strSql&"------<br>"
		Set jsonObj= QueryToJSON(Conn, strSql)
 
 	elseif "add"=act then ''增加
		jsonObj("msg") = "&#x64CD;&#x4F5C;&#x5931;&#x8D25;&#xFF0C;&#x8BF7;&#x91CD;&#x8BD5;..."'''' "操作失败，请重试..."
		jsonObj("success") = 0'"false"
		respagecode="dictionary_add"
		if not(check_Permissions(UserID,respagecode)) then 
			jsonObj("msg") = "权限受限，操作失败!"
			jsonObj("success") = 0'"false"
			jsonObj("url") = "../passport/nopermission.asp"
		else''添加信息		
			cid=ReplaceBadChar(Trim(request.Form("cid"))) ''id
			code=ReplaceBadChar(Trim(request.Form("code")))'' 
			cname=ReplaceBadChar(Trim(request.Form("cname")))'' 
			c_key=ReplaceBadChar(Trim(request.Form("c_key")))'' 
			c_txt=ReplaceBadChar(Trim(request.Form("c_txt")))''  			
			sort_num=ReplaceBadChar(Trim(request.Form("sort_num")))  
			pid=ReplaceBadChar(Trim(request.Form("p_id")))  
		
			''Dim rsObj,strSql
			set rsObj=Server.CreateObject("ADODB.Recordset")
			strSql = "Select  * from T_数据字典 where id='"&cid&"' "
			''Response.Write strSql&"-----"
			rsObj.Open strSql, Conn, 1, 3
			If rsObj.BOF And rsObj.EOF Then 
				rsObj.AddNew '如果没记录新增，有记录update	
				strSql = "select ISNULL(MAX(id), 0)  from [T_数据字典]  "
				cid = PE_CLng(Conn.Execute(strSql)(0)) + 1
			end if				
			''rsObj("id") = PE_CLng(cid)
			rsObj("code")=code  
			rsObj("name")=cname  
			rsObj("c_key")=c_key  
			rsObj("c_txt")=c_txt  
			rsObj("sort_num")=PE_CLng(sort_num)		
			rsObj("pid")=PE_CLng(pid)		
					
			rsObj.Update
			rsObj.close
			''Set rsObj = Nothing
		 
			jsonObj("msg") = "添加成功，正在跳转..."
			jsonObj("success") = 1'"success"
			jsonObj("url") = "dictionary.asp"
	 	 end if''权限判断end	 

elseif "edit"=act then'''修改
		jsonObj("msg") = "操作失败，请重试..."
		jsonObj("success") = 0'"false"
		respagecode="dictionary_edit"
		if not(check_Permissions(UserID,respagecode)) then 
			jsonObj("msg") = "权限受限，操作失败!"
			jsonObj("success") = 0'"false"
			jsonObj("url") = "../passport/nopermission.asp"			
		else''修改信息

			cid=ReplaceBadChar(Trim(request.Form("cid"))) ''id
			code=ReplaceBadChar(Trim(request.Form("code")))'' 
			cname=ReplaceBadChar(Trim(request.Form("cname")))'' 
			c_key=ReplaceBadChar(Trim(request.Form("c_key")))'' 
			c_txt=ReplaceBadChar(Trim(request.Form("c_txt")))''  			
			sort_num=ReplaceBadChar(Trim(request.Form("sort_num")))  
			pid=ReplaceBadChar(Trim(request.Form("p_id")))  
			 ''Response.Write cname&"----cname-<br>"
			''Dim rsObj,strSql
			''set rsObj=Server.CreateObject("ADODB.Recordset")
			strSql = "Select  * from [T_数据字典]  where id='"&cid&"' "
			''Response.Write strSql&"-----<br>"
			rsObj.Open strSql, Conn, 1, 3
			If rsObj.BOF And rsObj.EOF Then 
				jsonObj("msg") =  "操作失败，请重试..."
				jsonObj("success") = 0'"false"
				rsObj.close
			else				
				''rsObj("id") = PE_CLng(id)
				rsObj("code")=code  
				rsObj("name")=cname  
				rsObj("c_key")=c_key  
				rsObj("c_txt")=c_txt  
				rsObj("sort_num")=PE_CLng(sort_num)	 
				rsObj("pid")=PE_CLng(pid)	 
				
				rsObj.Update
				rsObj.close
				''Set rsObj = Nothing
		 
				jsonObj("msg") = "添加成功，正在跳转..."
				jsonObj("success") = 1'"success"
				jsonObj("url") = "dictionary.asp"			 	
			 	  
	 		end if	
		end if''权限判断end
			 	 
 elseif "delete"=act then''删除
 		respagecode="dictionary_del"
		if not(check_Permissions(UserID,respagecode)) then 
			jsonObj("msg") = "权限受限，操作失败!"
			jsonObj("success") = 0'"false"
			jsonObj("url") = "../passport/nopermission.asp"
		else''删除记录
		    ''Dim  RowCount 
			cid=ReplaceBadChar(Trim(request.Form("id"))) ''id
 
		    RowCount = 0
		    If (cid <> "" ) Then 
		    	Conn.Execute ("delete from [T_数据字典]  where id='"&cid&"'"), RowCount
		    End If
		    If RowCount = 0 Then
		        jsonObj("success") = 0 'false
		        jsonObj("msg") = "记录删除失败。" 
		    Else
		        jsonObj("msg") = "删除成功，正在跳转..." 
						jsonObj("success") = 1'"success"
						jsonObj("url") = "dictionary.asp"
		    End If '删除记录
  		end if''权限判断end
 
 
 
		 
  	End If

 
 

	'输出json对象
	jsonObj.Flush
	''Response.Write strSql&"-----"
 
	call CloseConn

''{
''    rslist : [ { name: "mac", desc: "computer",     
''                   price: 1000, quantity: 100, alert:null },
''                 { name: "ipod", desc: "music player", 
''                   price:  200, quantity: 200, alert:"on sale now!" },
''                 { name: "cinema display", desc: "screen",       
''                   price:  800, quantity: 300, alert:"best deal!" } ],
''    customer : { first: "John", last: "Public", level: "gold" }
''}

%>